//
//  ServiceMercTopVM.swift
//  kxf
//
//  Created by Mac on 2024/3/10.
//

import Foundation
import UIKit

class ServiceMercTopVM: UIView {
    
    let selfHeight = kFitWidth(214)+WHBaseViewVC().getTopSafeAreaHeight()

    override init(frame:CGRect){
        super.init(frame: CGRect.init(x: 0, y: 0, width: SCREEN_WIDHT, height: selfHeight))
        self.backgroundColor = .clear
        self.isUserInteractionEnabled = true
        
        initUI()
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    lazy var bgImgView : UIImageView = {
        let img = UIImageView()
        img.setImgLocal(imgName: "market_mange_top_bg")
        img.isUserInteractionEnabled = true
        return img
    }()
    lazy var titleLabel : UILabel = {
        let lab = UILabel()
        lab.text = "服务商"
        lab.textColor = .white
        lab.font = .systemFont(ofSize: 18, weight: .medium)
        
        return lab
    }()
    lazy var headImgView : UIImageView = {
        let img = UIImageView()
        img.setImgLocal(imgName: "avatar_default")
        return img
    }()
    lazy var nameLabel : UILabel = {
        let lab = UILabel()
        lab.textColor = .white
        lab.font = .systemFont(ofSize: 16, weight: .medium)
        
        return lab
    }()
}

extension ServiceMercTopVM{
    func updateUI() {
        nameLabel.text = "\(UserModel.shared.agentName)[\(UserModel.shared.izSichuanName)]"
    }
}
extension ServiceMercTopVM{
    func initUI() {
        addSubview(bgImgView)
        bgImgView.addSubview(titleLabel)
        bgImgView.addSubview(headImgView)
        bgImgView.addSubview(nameLabel)
        
        setConstrait()
    }
    func setConstrait() {
        bgImgView.snp.makeConstraints { make in
            make.left.top.width.height.equalToSuperview()
        }
        titleLabel.snp.makeConstraints { make in
            make.centerX.lessThanOrEqualToSuperview()
            make.top.equalTo(kFitWidth(20)+WHBaseViewVC().getTopSafeAreaHeight())
            make.height.equalTo(kFitWidth(44))
        }
        headImgView.snp.makeConstraints { make in
            make.centerX.lessThanOrEqualToSuperview()
            make.top.equalTo(titleLabel.snp.bottom).offset(kFitWidth(20))
            make.width.height.equalTo(kFitWidth(80))
        }
        nameLabel.snp.makeConstraints { make in
            make.centerX.lessThanOrEqualToSuperview()
            make.top.equalTo(headImgView.snp.bottom).offset(kFitWidth(12))
        }
    }
}
